<script>
export default {
  onLaunch: function () {
    console.log("App Launch");
    uni.checkSession({
      success() {
        console.log("已登录");
      },
      fail() {
        // 微信登录
        uni.login({
          provider: "weixin",
          success: (res) => {
            var code = res.code;
            uni.request({
              url:
                "https://api.weixin.qq.com/sns/jscode2session?appid=?&secret=?&js_code=" +
                code +
                "&grant_type=authorization_code",
              method: "GET",
              data: {},
              success: (res) => {
                var wxCode = res.data.openid;
                var sessionKey = res.data.session_key;
                var wxUserInfo = {};
                wxUserInfo.userWxOpenid = wxCode;
                try {
                  // uni.setStorageSync('wxCode', wxCode)
                  uni.setStorageSync("sessionKey", sessionKey);
                  uni.setStorageSync("wxUserInfo", wxUserInfo);
                  // console.log(wxUserInfo)
                } catch (e) {
                  //TODO handle the exception
                  console.log(e);
                }
                console.log("已登录");
              },
              fail: () => {},
              complete: () => {},
            });
          },
          fail: () => {
            console.log("登录失败……");
          },
          complete: () => {},
        });
      },
    });
  },
  // onShow: function() {
  // 	console.log('App Show')
  // },
  // onHide: function() {
  // 	console.log('App Hide')
  // }
};
</script>

<style>
/*每个页面公共css */
.page {
  width: 100%;
  height: 100%;
  /* display: flex;
		flex-direction: column; */
  /* overflow: hidden; */
}

@font-face {
  font-family: iconfont;
  /* src: url('~@/static/iconfont.ttf'); */
  src: url("https://at.alicdn.com/t/font_1249777_8c28ci72cj3.ttf")
    format("truetype");
}

.iconfont {
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>
